<?php
/**
 * | ---------------------------------------------------------------------------------------------------
 * | Author：johnxu <fsyzxz@163.com>.
 * | ---------------------------------------------------------------------------------------------------
 * | Home: https://www.johnxu.net.
 * | ---------------------------------------------------------------------------------------------------
 * | Data: 2018/12/31
 * | ---------------------------------------------------------------------------------------------------
 * | Desc: 异步redis操作
 * | ---------------------------------------------------------------------------------------------------
 * | Document: https://wiki.swoole.com/wiki/page/p-async.html
 * | ---------------------------------------------------------------------------------------------------
 */

$redis = new Swoole\Redis( array(
    'password' => '123456'
) );

$redis->connect( '127.0.0.1', 6379, function ( \Swoole\Redis $redis, bool $result ) {
    var_dump( $result );

    // 設置值
    $redis->set( 'key', 'swoole', function ( \Swoole\Redis $redis, $result ) {
        var_dump( $result );

    } );

    // 獲取值
    $redis->get( 'key', function ( \Swoole\Redis $redis, $result ) {
        var_dump( $result );
    } );
    $redis->close();
} );

echo 'start redis' . PHP_EOL;
